﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using MishraReader.ViewModels.Tools;

namespace MishraReader.PlatformVMs
{
    internal class WrappedCollectionViewSource : IWrappedCollectionViewSource
    {
        private readonly CollectionViewSource _source = new CollectionViewSource();
        private readonly WrappedView _view;

        public WrappedCollectionViewSource()
        {
            _view = new WrappedView(_source);
        }

        public object Source
        {
            get { return _source.Source; }
            set { _source.Source = value; }
        }

        public object UnderlyingSource
        {
            get { return _source; }
        }

        public IWrappedCollectionView View
        {
            get
            {
                if (_source.View == null)
                    return null;
                return _view;
            }
        }

        private class WrappedView : IWrappedCollectionView
        {
            private readonly CollectionViewSource _source;

            public WrappedView(CollectionViewSource source)
            {
                _source = source;
            }

            public bool MoveCurrentTo(object item)
            {
                return _source.View.MoveCurrentTo(item);
            }

            public bool MoveCurrentToPosition(int position)
            {
                return _source.View.MoveCurrentToPosition(position);
            }

            public bool IsCurrentAfterLast
            {
                get { return _source.View.IsCurrentAfterLast; }
            }

            public bool MoveCurrentToFirst()
            {
                return _source.View.MoveCurrentToFirst();
            }

            public bool IsCurrentBeforeFirst
            {
                get { return _source.View.IsCurrentBeforeFirst; }
            }

            public bool MoveCurrentToLast()
            {
                return _source.View.MoveCurrentToLast();
            }

            public bool MoveCurrentToNext()
            {
                return _source.View.MoveCurrentToNext();
            }

            public bool MoveCurrentToPrevious()
            {
                return _source.View.MoveCurrentToPrevious();
            }
        }
    }
}